package com.hzsparrow.business.base.config.shiro;

import com.hzsparrow.business.base.contant.BaseBusinessCodeEnum;
import com.hzsparrow.framework.model.result.ResultDTO;
import com.hzsparrow.framework.utils.JsonUtils;
import org.apache.shiro.web.filter.authc.FormAuthenticationFilter;

import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import java.io.IOException;

public class HzsparrowShiroFormAuthenticationFilter extends FormAuthenticationFilter {

    @Override
    protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
        ResultDTO<Object> result = ResultDTO.getDataFaild(BaseBusinessCodeEnum.NOT_LOGIN.getCode(), BaseBusinessCodeEnum.NOT_LOGIN.getMsg(), null);
        response.setContentType("application/json;charset=utf-8");
        response.getWriter().println(JsonUtils.serialize(result));
    }

}
